<!--

Copyright 2016 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<!DOCTYPE html>
<html>
<head>
<style>

/* CSS perspective parallax demo. This demo outlines all of the workarounds
 * necessary to get perspective parallax working performantly in Chrome, Edge,
 * Firefox and Safari.
 *
 * Outstanding issues:
 * - Edge developer tools is showing a Paint of <root> with the bounds of the
 *   window.
 */

html, body {
  margin:0;
  padding:0;
  height: 100%;
}

body {
  /* Without this compositing trigger, Edge does not correctly parallax until
     a repaint is triggered otherwise. */
  transform: translateZ(0);
}

#overflow {
  height: 100%;
  overflow-y: scroll;
  overflow-x: hidden;
	-webkit-overflow-scrolling: touch;
}

#parallax {
  background: 50% 50% / cover;
  background-image: url('images/header-park.jpg');
  position: relative;
  transform: translateZ(-2px) scale(3);
  transform-style: preserve-3d;
  transform-origin: 0% 0% 0px;
  height: 400px;
  width: 100%;
}

#container {
  position: relative;
}

#content {
  background: white;
  height: 3000px;
  position: relative;
}

.magic-fixed-pixel {
  /* Without this fixed position element, Edge does not correctly update the
     parallax position until it is forced to repaint. */
  position: fixed;
  top: 0;
  width: 1px;
  height: 1px;
  z-index: 1;
}

/* This magic pixel div is necessary to get the #content div to paint its
   background to the top of its bounds. Otherwise the background is only painted
   where the content starts (excluding margins). */
.magic-pixel {
  width: 1px;
  height: 1px;
}

.box {
  margin: 10% 15%;
  border: 3px solid #aaa;
  padding: 10%;
}

.overflow-parallax #overflow,
.sticky-parallax #container {
  perspective: 1px;
  perspective-origin: 0% 0%;
}

.overflow-parallax #container {
  transform-style: preserve-3d;
}

.sticky-parallax #parallax {
  position: -webkit-sticky;
  top: 0;
}

</style>
<script>
document.addEventListener('DOMContentLoaded', function() {
  var parallaxElement = document.getElementById('parallax');
  if (getComputedStyle(document.getElementById('overflow')).webkitOverflowScrolling) {
    document.body.classList.add('sticky-parallax');
  } else {
    document.body.classList.add('overflow-parallax');
  }
});
</script>
</head>

<body>
<div class="magic-fixed-pixel"></div>
<div id="overflow">
    <div id="container">
      <div id="parallax"></div>
      <div id="content">
        <div class="magic-pixel"></div>
        <div class="box">Content</div>
        <div class="box">in</div>
        <div class="box">boxes</div>
        <div class="box">to</div>
        <div class="box">make</div>
        <div class="box">the</div>
        <div class="box">page</div>
        <div class="box">scroll</div>
      </div>
    </div>
</div>
</body>
</html>